﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Rubyer;
using StockUI.Model;
using StockUI.Views;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Xml;

namespace StockUI.ViewModels
{
    /// <summary>
    /// 股票数据
    /// </summary>
    public partial class GpsjViewModel : ObservableObject
    {
        [ObservableProperty]
        private ObservableCollection<StockModel> stockSZItem;

        [ObservableProperty]
        private ObservableCollection<StockModel> stockSCItem;


        [ObservableProperty]
        private ObservableCollection<TabItem> tabsItem;


        [ObservableProperty]
        private TabItem selectedTabs;


        public GpsjViewModel()
        {
            StockSZItem = new ObservableCollection<StockModel>
            {
                new StockModel{Title = "中粮科工",Code = "01"},
                new StockModel{ Title = "赛托生物", Code = "02"},
                new StockModel{ Title = "奥晒科技", Code = "03"}
            };
            StockSCItem = new ObservableCollection<StockModel>
            {
                new StockModel{Title = "中粮科工",Code = "01"},
                new StockModel{ Title = "赛托生物", Code = "02"},
                new StockModel{ Title = "奥晒科技", Code = "03"}
            };
            //SelectedTabs = new TabItem { Header = "今日复盘", Tag = "Home", Content = new Home() };
            TabsItem = new ObservableCollection<TabItem> {
            }; 
        }

        [RelayCommand]
        private async Task AddItem(object item)
        {
            var addmodel = item as StockModel;
            SelectedTabs = new TabItem { Header = addmodel.Title, Tag = addmodel.Code, Content = new TabCommon() };
            TabsItem.Add(SelectedTabs);
        }

       
        /// <summary>
        /// 移除命令
        /// </summary>
        [RelayCommand]
        private async Task RemoveItem(TabItem poetry)
        {
            //var result = await MessageBoxR.Confirm("是否删除?");
           
            //if (result == MessageBoxResult.Yes)
            //{
                var tab=TabsItem.Where(a => a.Tag == poetry.Tag).First();
                TabsItem.Remove(tab);
            //if (SelectedTabs.Tag.ToString() != "Home")
            //{
            //    SelectedStock = new StockModel { Title = SelectedTabs.Header.ToString(), Code = SelectedTabs.Tag.ToString() };
            //}
            //else
            //{
            //    SelectedStock = new StockModel { Title = "今日复盘", Code = "Home" }; 
            //}
            // }
        }
    }
 
}
